#include<iostream>
#include<unistd.h>
#include<pthread.h>
#include<functional>
#include<cassert>
#include<queue>
#include<string>

class Thread
{
    typedef std::function<void*(void*)> func_t;
public:
static int num;
    Thread()
    {
        char name[64];
        snprintf(name,sizeof name,"Thread %d",num++);
        _name=name; //线程名字
        //设置线程函数的参数
    }

    std::string getname() //用于给返回名字
    {
        return _name; 
    }
    void start(func_t func,void*arg)
    {
        _func=func;
        _arg=arg;
        int n = pthread_create(&_tid,nullptr,mystart,this);
        assert(n==0);
        (void)n;
    }

    void join(void** ret)
    {   
        int n = pthread_join(_tid,ret);
        assert(n==0);
        (void)n;
    }

private:
    static void* mystart(void* pt)
    {
        Thread* t=static_cast<Thread*>(pt);
        return t->_func(t->_arg);
    }
private:
    pthread_t _tid;
    func_t _func;
    void* _arg;
    std::string _name;
};
int Thread:: num=1;